package com.cindata

class TimingTaskJob
{
    def timingTaskService
    static triggers = {
        cron name: 'everydayTrigger', startDelay: 10000, cronExpression: '0 0 0 * * ?'  // 每天凌晨零点
        cron name: 'weeklyTrigger', startDelay: 10000, cronExpression: '0 0 0 ? * 2'    // 每周一凌晨零点
        cron name: 'monthlyTrigger', startDelay: 10000, cronExpression: '0 0 0 1 * ?'   // 每月一号凌晨零点
        
        cron name: 'minuteTrigger', startDelay: 10000, cronExpression: '0 * * * * ?'    // 每分钟
        cron name: 'hourTrigger', startDelay: 10000, cronExpression: '0 0 * * * ?'      // 每小时
        cron name: 'yearTrigger', startDelay: 10000, cronExpression: '0 0 0 1 1 ?'      // 每年一月一日凌晨零点
        cron name: 'quarterTrigger', startDelay: 10000, cronExpression: '0 0 0 1 1,4,7,10 ?' // 每月1,4,7,10月1日凌晨零点
    }

    def execute(context)
    {
        def currentTrigger = context.trigger.key.name
        if (currentTrigger == 'minuteTrigger')
        {
            // println "minute"
            // timingTaskService.executeRiskWarning "minute"
        }
        else if (currentTrigger == 'hourTrigger')
        {
            // println "hour"
            // timingTaskService.executeRiskWarning "hour"
        }
        else if (currentTrigger == 'everydayTrigger')
        {
            println "day"
            timingTaskService.executeRiskWarning "day"
        }
        else if (currentTrigger == 'weeklyTrigger')
        {
            println "week"
            timingTaskService.executeRiskWarning "week"
        }
        else if (currentTrigger == 'monthlyTrigger')
        {
            println "month"
            timingTaskService.executeRiskWarning "month"
        }
        else if (currentTrigger == 'quarterTrigger')
        {
            println "quarter"
            timingTaskService.executeRiskWarning "quarter"
        }
        else if (currentTrigger == 'yearTrigger')
        {
            println "year"
            timingTaskService.executeRiskWarning "year"
        }
    }
}